import sys
from os.path import abspath, join, dirname
# 插入proto目录到sys.path
sys.path.insert(0, join(abspath(dirname(__file__)), "../"))
from mqtt.mqtt_publish import MqttPublish

from mqtt.common.common_constant import CommonConstant
from mqtt.method.control_fly_method import ControlFlyMethodEnum
class DroneApi:
    def __init__(self):
        self.mqtt_publish = MqttPublish()

    # 请求授权云端控制
    def cloud_control_auth_request(self, gateway_sn, request):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data=request,
                                              method=ControlFlyMethodEnum.CLOUD_CONTROL_AUTH_REQUEST.get_method())

    # 释放云端控制
    def cloud_control_release(self, gateway_sn, request):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data=request,
                                              method=ControlFlyMethodEnum.CLOUD_CONTROL_RELEASE.get_method())


    # 进入指令飞行控制模式
    def drc_mode_enter(self, gateway_sn, request):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data=request,
                                              method=ControlFlyMethodEnum.DRC_MODE_ENTER.get_method())



    # 退出指令飞行控制模式
    def drc_mode_exit(self, gateway_sn, request):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data=request,
                                              method=ControlFlyMethodEnum.DRC_MODE_EXIT.get_method())


    # 一键起飞
    def takeoff_to_point(self, gateway_sn, request):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data=request,
                                              method=ControlFlyMethodEnum.TAKEOFF_TO_POINT.get_method())


    # 飞向目标点
    def fly_to_point(self, gateway_sn, request):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data=request,
                                              method=ControlFlyMethodEnum.FLY_TO_POINT.get_method())

    # 结束 flyto 飞向目标点任务
    def fly_to_point_stop(self, gateway_sn):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data={},
                                              method=ControlFlyMethodEnum.FLY_TO_POINT_STOP.get_method())


    # 更新 flyto 目标点
    def fly_to_point_update(self, gateway_sn, request):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data=request,
                                              method=ControlFlyMethodEnum.FLY_TO_POINT_UPDATE.get_method())

    # 一键返航
    def return_home(self, gateway_sn):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data=None,
                                              method=ControlFlyMethodEnum.RETURN_HOME.get_method())


    # 取消一键返航
    def return_home_cancel(self, gateway_sn):
        self.mqtt_publish.publish_with_method(gateway_sn=gateway_sn,
                                              suffix=CommonConstant.TOPIC_SERVICES_SUFFIX,
                                              data={},
                                              method=ControlFlyMethodEnum.RETURN_HOME_CANCEL.get_method())
